package com.zhu.service.edu.ThreadLocalService;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zhu.service.edu.feign.AliyunVodFeign;
import com.zhu.service.edu.mapper.EduCourseMapper;
import com.zhu.service.edu.mapper.EduVideoMapper;
import com.zhu.service.edu.pojo.EduVideo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;


@Component
@Slf4j
public class VideoDeleteThreadLocal {
    @Async("taskExecutor")
    public void deleteVideos(EduVideoMapper videoMapper, AliyunVodFeign aliyunVodFeign,String id) throws Exception {
        LambdaQueryWrapper<EduVideo> queryWrapper1=new LambdaQueryWrapper<>();
        queryWrapper1.eq(EduVideo::getChapterId,id);
        List<EduVideo> eduVideos = videoMapper.selectList(queryWrapper1);
        List<String>  videoSourceIdList=new ArrayList<>();
        eduVideos.forEach(eduVideo->{
            String videoSourceId = eduVideo.getVideoSourceId();
             videoSourceIdList.add(videoSourceId);
        });
        aliyunVodFeign.deleteVideoList(videoSourceIdList);
        log.info("视频删除成功！：{}",videoSourceIdList);
    }
    @Async("taskExecutor")
    public void deleteVideoByList(String id, AliyunVodFeign aliyunVodFeign,
                                  EduCourseMapper courseMapper, EduVideoMapper videoMapper) {
         LambdaQueryWrapper<EduVideo> queryWrapper=new LambdaQueryWrapper<>();
        List<String>  videoSourceIdList=new ArrayList<>();
         queryWrapper.eq(EduVideo::getCourseId, id);
        List<EduVideo> eduVideos = videoMapper.selectList(queryWrapper);
        eduVideos.forEach(video -> {
            String videoSourceId = video.getVideoSourceId();
            videoSourceIdList.add(videoSourceId);
        });
        try {
            aliyunVodFeign.deleteVideoList(videoSourceIdList);
            log.info("视频删成功：{}",videoSourceIdList);
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }
}
